package caddey.jonathan.gameframeworkandroidimplementation;

import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.util.Log;
import framework.GameContext;
import framework.GraphicsWrapper;
import framework.KInput;
import framework.ResourcesWrapper;
import framework.Screen;

public abstract class AndroidGameContext extends Activity implements GameContext {
	private Screen my_screen;
	private AndroidGraphics my_graphics;
	private KInput my_input;
	private AndroidResources my_resources;
	private GameView my_gameView;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		final int width;
		final int height;
		if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
			width = 480;
			height = 800;
		} else {
			width = 800;
			height = 480;
		}
		Bitmap bitmap = Bitmap.createBitmap(width,
	            height, Config.RGB_565);
		Log.d("HELLO", "aaaah! " + width);
		my_gameView = new GameView(this, bitmap);
		my_graphics = new AndroidGraphics(bitmap);
		my_resources = new AndroidResources(this);
		my_screen = getInitialScreen();
		setContentView(my_gameView);
		my_input = new KAndroidInput(this, my_gameView, 1, 1);
	}
	@Override
	protected void onResume() {
		super.onResume();
		my_resources = new AndroidResources(this);
		my_gameView.resume();
	}
	protected void onPause() {
		super.onPause();
		my_resources = null;
		my_gameView.pause();
	}
	
	@Override
	public void setScreen(Screen the_screen) {
		my_screen = the_screen;
	}

	@Override
	public Screen getCurrentScreen() {
		return my_screen;
	}

	@Override
	public GraphicsWrapper getGraphicsWrapper() {
		return my_graphics;
	}
	
	@Override
	public KInput getInput() {
		return my_input;
	}
	
	@Override
	public ResourcesWrapper getResourcesWrapper() {
		return my_resources;
		
	}
}
